

#!/bin/bash

OK=false
echo -n "Test 2 - ADD ..... "

../../spblaze -t kcpsm3 -o test2 -x test2.hex > output2.txt 2> error2.txt < commands.txt

# REGISTERS
RESULT=$(xml_grep --text_only '//regbank' test2_state.xml)
RESULT=${RESULT:0:32}
EXPECTED=$(xml_grep --text_only '//regbank' test2_state_expected.xml)
EXPECTED=${EXPECTED:0:32}

# PC
RESULT_PC=$(xml_grep --text_only '//pc' test2_state.xml)
EXPECTED_PC=$(xml_grep --text_only '//pc' test2_state_expected.xml)

# C
RESULT_C=$(xml_grep --text_only '//carry' test2_state.xml)
EXPECTED_C=$(xml_grep --text_only '//carry' test2_state_expected.xml)

# Z
RESULT_Z=$(xml_grep --text_only '//zero' test2_state.xml)
EXPECTED_Z=$(xml_grep --text_only '//zero' test2_state_expected.xml)

if [ $RESULT = $EXPECTED -a $RESULT_PC = $EXPECTED_PC -a $RESULT_C = $EXPECTED_C -a $RESULT_Z = $EXPECTED_Z ]
then        
  OK=true
  echo "OK"
else
  echo "FAIL"
fi

if $OK
then
  exit 0
else
  exit 1
fi

 